import {Component, OnInit} from '@angular/core';
import {NzMessageService} from 'ng-zorro-antd';
import {ActivatedRoute} from '@angular/router';
import {RoleService} from '../role.service';

@Component({
    selector: 'app-list',
    templateUrl: './list.component.html',
})
export class ListComponent implements OnInit {
    data: any[] = [];

    constructor(private roleService: RoleService,
                private route: ActivatedRoute,
                private msg: NzMessageService) {
    }

    ngOnInit() {
        this.getList();
    }

    /**
     * 得到角色列表
     */
    getList() {
        this.roleService.getRoleList().subscribe(res => {
            this.data = res['list'];
        });
    }

    /**
     * 删除角色
     * @param i
     */
    delRole(resource) {
        const index = this.data.indexOf(resource);
        this.data = [...this.data.slice(0, index), ...this.data.slice(index + 1, this.data.length)];
        this.roleService.delRole(resource.id).subscribe(res => {
            this.msg.success('删除成功');
            // this.getList(this.pageCurrent);
        }, __ => {
            // this.msg.error('删除失败');
            this.roleService.getRoleList();
        });
    }

}
